package view.confirmaciones;

import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

public class ViewDialog extends JDialog {

	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private JTextArea textArea;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			ViewDialog dialog = new ViewDialog(DialogTypes.positive, "Curso creado exitosamente \nCurso creado exitosamente\nCurso creado exitosamente\nCurso creado exitosamente\nCurso creado exitosamente\nCurso creado exitosamente\nCurso creado exitosamente");
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public ViewDialog(DialogTypes type, String comment) {
		setIconImage(Toolkit.getDefaultToolkit().getImage(ViewDialog.class.getResource(type.getPathIcon())));
		setAlwaysOnTop(true);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setResizable(false);
		setModal(true);
		setBounds(650, 400, 350, 100);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		setLocationRelativeTo(null);
		contentPanel.setLayout(new BorderLayout(0, 0));

		textArea = new JTextArea();
		textArea.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
		textArea.setBorder(null);
		textArea.setText(comment);
		textArea.setBackground(UIManager.getColor("Panel.background"));
		textArea.setColumns(10);
		textArea.setFont(new Font("Tahoma", Font.PLAIN, 14));
		textArea.setBounds(50, 20, 254, 14);
		textArea.setLineWrap(true);
		textArea.setWrapStyleWord(true);

		JScrollPane scrollTextArea = new JScrollPane();
		scrollTextArea.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		scrollTextArea.setViewportView(this.textArea);
		scrollTextArea.setBounds(50, 20, 254, 14);
		contentPanel.add(scrollTextArea);

		Rectangle bount = getBounds();
		int count = textArea.getLineCount();
		if (count > 1) {
			if (count > 3) {
				setBounds(bount.x, bount.y, (3 * 15) + bount.width, (3 * 15) + bount.height);
			}else{
				
				setBounds(bount.x, bount.y, (count * 15) + bount.width, (count * 15) + bount.height);
			}
		}
		JPanel buttonPane = new JPanel();
		buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
		getContentPane().add(buttonPane, BorderLayout.SOUTH);
		JButton okButton = new JButton("OK");
		okButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		});
		okButton.setActionCommand("OK");
		buttonPane.add(okButton);
		getRootPane().setDefaultButton(okButton);
		this.setVisible(true);
	}
}
